********************************************************************************
********************************************************************************
* Title:		regressions
* Project:		Stress, Ethnicity, and Prosocial Behavior
* Author:		Moritz Poll (moritz.poll@brown.edu)
* PIs:			Johannes Haushofer, Sara Lowes, Abednego Musau, David Ndetei, 
*				Nathan Nunn, Moritz Poll, Nancy Qian
* Purpose:		Full set of regressions in all specifications
********************************************************************************
********************************************************************************

noisily dis as input "Start: Regressions"

global noisyregs "" // noisily
set more off
set trace off

********************************************************************************
************ Main specification 1 & 2 and robustness (full sample) *************
********************************************************************************

forvalues spec = 1 / 2 { // Specifications 1 (between) and 2 (within)
	if `spec' == 1 local robustness_checks `""_first_same" "_first_diff" "_low_edu" "_high_edu" "_coa07" "_coa17" "_sessionfe" "_parents_same" "_comprehension" "_viewtime" "_decisiontime" "_continuetime" "_imbalance" "_welsch""'
	else local robustness_checks ""
	foreach game in $main_table_vars { // Games
		if "`game'" == "cyd" & `spec' == 2 continue // Not identified
		use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear
		replace round = round + 0.0 if game == 5
		replace round = round + 0.1 if game == 6
		replace round = round + 0.2 if game == 7
		replace round = round + 0.3 if game == 8
		replace round = round + 0.4 if game == 9
		noisily dis as result _n "Successfully run regression specification `spec' `game'" _continue
		foreach rest in "" `robustness_checks' { // Restrictions: Session FEs for specification 1 as well as sample splits
			
			include "$do_analysis_dir/sample_restrictions.do"
			if "`game'" != "social_proximity" & "`game'" != "cyd" local y "share"
			else local y "decision"
			
			preserve
			keep if game_str == "`game'"
			if "`game'" == "tg2" replace round = 10*round if round != 1 // Make rounds integer
			
			if `spec' == 2 & "`game'" != "cyd" xtset ID round
			
			include "$do_analysis_dir/main`spec'.do"

			estimates save "$estimates_dir/`game'_spec`spec'`rest'", replace
			noisily dis as result ", `rest'" _continue
			restore
		}
	}
	noisily dis as result "."
}

********************************************************************************
********************* Main specification 1 without controls ********************
********************************************************************************

reg decision _same_eth c._same_eth#treatment if game == 2, cluster(ID)
estimates save "$estimates_dir/cyd_spec1_nocontrols", replace
foreach game in dg tg1 tg2 social_proximity {
	reg share _same_eth##treatment if game_str == "`game'", cluster(ID)
	estimates save "$estimates_dir/`game'_spec1_nocontrols", replace
}
foreach game in likely_to_be_friends closeness trust {
	reg decision _same_eth##treatment if game_str == "`game'", cluster(ID)
	estimates save "$estimates_dir/`game'_spec1_nocontrols", replace
}

********************************************************************************
*********************** Choose Your Dictator Game logit ************************
********************************************************************************

use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear
include "$do_analysis_dir/sample_restrictions.do"
local v _same_eth  _same_coa07  _same_coa17  _same_sex  _same_age  $cyd_controls
foreach var in `v' {
	capture rename `var' `var'0
	rename cyd_diff`var' `var'
}
foreach var in _same_eth  _same_coa07  _same_coa17  _same_sex  _same_age {
	rename hydro`var' hydro`var'0
	gen hydro`var' = treatment * `var'
}
keep if game_str == "cyd"
logit   decision _same_eth  hydro_same_eth  _same_sex  hydro_same_sex  _same_age  hydro_same_age  $cyd_controls `if_restriction', cluster(ID)
estimates save "$estimates_dir/cyd_spec1_logit", replace
noisily dis as result "Successfully run regression CYD logit specification."

********************************************************************************
************************** Experimenter Demand Module **************************
********************************************************************************
* At the end of each laboratory session, all participants were asked to play one
* more round of the DG. Half the sample received the following additional 
* instruction right before making the allocation decision:
* "You are participating in this study in groups. We expect that people in your
* group will give more than they otherwise would." Here we test whether this had
* any effect on behavior.
********************************************************************************

use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear
include "$do_analysis_dir/sample_restrictions.do"
keep if game_str == "demand"
foreach spec in "" "treatment0" "treatment1" "_same_eth0" "_same_eth1" {
	if "`c'" == "_controls" local controls $controls
	else local controls
	if "`spec'" == "" 				local if
	if "`spec'" == "treatment0"  	local if "if !treatment"
	if "`spec'" == "treatment1" 	local if "if  treatment"
	if "`spec'" == "_same_eth0" 	local if "if !_same_eth"
	if "`spec'" == "_same_eth1" 	local if "if  _same_eth"

	reg share demandeffects `controls' `if', cluster(ID) noomitted // clustering is not necessary but helps keeps table generation consistent
	estimates save "$estimates_dir/demand`spec'`controls'", replace
}
noisily dis as result "Successfully run demand module regressions."

********************************************************************************
*********************** Trust Game 2 by amount allocated ***********************
********************************************************************************
* The first column introduces game fixed effects into the standard regression,
* while the remaining five split the sample into the decisions for each possible
* amount allocated.
********************************************************************************

local spec = 1
use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear
include "$do_analysis_dir/sample_restrictions.do"
local cluster cluster(ID)
local game tg2
keep if game_str == "`game'"
replace round = round + 0.1 if game == 5
replace round = round + 0.2 if game == 6
replace round = round + 0.3 if game == 7
replace round = round + 0.4 if game == 8
replace round = round + 0.5 if game == 9
replace round = 10 * round if game_str == "tg2"
xtset ID round
local y share
local if_restriction ""
local fe "i.game"
include "$do_analysis_dir/main`spec'.do"
estimates save "$estimates_dir/`game'_spec`spec'_game_fe", replace
local fe ""
foreach allocation in 120 240 360 480 600 {
	local if_restriction "if game == `=4+`allocation'/120'"
	include "$do_analysis_dir/main`spec'.do"
	estimates save "$estimates_dir/`game'_spec`spec'_`allocation'", replace
	local if_restriction ""
}
noisily dis as result "Successfully run tg2 regressions by amount allocated specification `spec'."

********************************************************************************
************************** Trust Game 2 by game order **************************
********************************************************************************

local spec = 1
use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear
include "$do_analysis_dir/sample_restrictions.do"
local cluster cluster(ID)
local game tg2
keep if game_str == "`game'"
replace round = round + 0.1 if game == 5
replace round = round + 0.2 if game == 6
replace round = round + 0.3 if game == 7
replace round = round + 0.4 if game == 8
replace round = round + 0.5 if game == 9
replace round = 10 * round if game_str == "tg2"
xtset ID round
local y share
foreach order in 1 2 {
	local if_restriction "if ts_taskorder == `order'"
	include "$do_analysis_dir/main`spec'.do"
	estimates save "$estimates_dir/`game'_spec`spec'_`order'", replace
	local if_restriction ""
}
noisily dis as result "Successfully run tg2 regressions by task order specification `spec'."

********************************************************************************
******************** Social Proximity by individual measure ********************
********************************************************************************

local cluster cluster(ID)
local fe ""
local y decision
local spec = 1
foreach game in likely_to_be_friends trust closeness {
	use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear
	include "$do_analysis_dir/sample_restrictions.do"
	keep if game_str == "`game'"
	xtset ID round
	include "$do_analysis_dir/main`spec'.do"
	estimates save "$estimates_dir/`game'_spec`spec'", replace
	noisily dis as result "Successfully run `game' regressions specification `spec'."
}

********************************************************************************
******************** Ethnicity, age, and gender interactions *******************
********************************************************************************

use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear
include "$do_analysis_dir/sample_restrictions.do"
local spec = 1
local cluster cluster(ID)
gen _same_eth_same_sex = _same_eth * _same_sex
gen _same_eth_same_age = _same_eth * _same_age
foreach game in $main_table_vars {
	preserve
	keep if game_str == "`game'"
	local if_restriction "_same_eth##_same_sex  _same_eth##_same_age"
	if "`game'" == "cyd" local if_restriction "_same_eth_same_sex  _same_eth_same_age"
	local y share
	if "`game'" == "social_proximity" local y decision
	include "$do_analysis_dir/main`spec'.do"
	estimates save "$estimates_dir/`game'_spec`spec'_sex_age_interaction", replace
	restore
}

********************************************************************************
********* Trust Game 1 behavior controlling for Dictator Game behavior *********
********************************************************************************

include "$do_analysis_dir/sample_restrictions.do"
local cluster cluster(ID)
local fe ""
local if_restriction dg_share_inoutgroup
local y share
local game tg1
local spec = 1
use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear
keep if game_str == "`game'"
xtset ID round
include "$do_analysis_dir/main`spec'.do"
estimates save "$estimates_dir/tg1_spec`spec'_dg_control", replace
noisily dis as result "Successfully run `game' regressions specification `spec'."

noisily dis as input "End: Regressions"
